//#pragma once

#ifndef __STRING_H__
#define __STRING_H__

#include <iostream>
using namespace std;

namespace yyp
{
	class string
	{
	public:
		string(const char* s = "")
			:_str(nullptr)
			, _size(0)
			, _capacity(0)
		{
			int sz = strlen(s);
			reserve(sz);

			if (sz)
			{
				for (int i = 0; i < sz; ++i)
				{
					_str[i] = s[i];
				}

				_size += sz;
			}
		}

		string(string& s)
		{

		}

		~string()
		{
			_str = nullptr;
			_size = _capacity = 0;
		}

		void push_back(char c)
		{
			if (_size == _capacity)
			{
				size_t newcapacity = _capacity == 0 ? 4 : 2 * _capacity;
				char* tmp = new char[newcapacity];
				memcpy(tmp, _str, _size * sizeof(char));
				delete _str;

				_str = tmp;
				_capacity = newcapacity;
			}

			_str[_size++] = c;
			_str[_size] = '\0';
		}

		void reserve(size_t n = 0);

		bool empty()
		{
			return _size == 0;
		}






	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
}


#endif
